package com.itheima.tcp;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class SocketDemoFour03 {
    public static void main(String[] args) throws IOException {
        //网络中的流，从客户端读取数据
        ServerSocket serverSocket = new ServerSocket(1000);
        ThreadPoolExecutor thpool = new ThreadPoolExecutor(
                3,
                4,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        while (true) {
            Socket accept = serverSocket.accept();
            ThreadRuned threadRuned = new ThreadRuned(accept);
//            Thread thread=new Thread(threadRuned);
//            thread.start();
            //new Thread(threadRuned).start();
            thpool.submit(threadRuned);
        }
        //serverSocket.close();
    }
}
